<?php
class RM_User_AmenitiesController extends RM_Controller
{
    public function getunitamenitiesJsonAction(){
        $unitID =  $this->_getParam('unitID');
        $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale());
        $model = new RM_Amenities();
        $amenitiesArray = $model->getbyUnit($unitID,$iso);

        $config = new RM_AmenitiesConfig();
        $settings = $config->fetchAll("id='1'")->current()->toArray();

        return array(
            'data' => array("amenities"=>$amenitiesArray,'config' => $settings)
        );
    }

    public function getamenitiesJsonAction(){
        $model = new RM_Amenities();
        $data = $model->getAll()->toArray();
        
        foreach($data as $item){
            $newData[] = array("id"=>$item[id],"name"=>$item[RM_Environment::getInstance()->getLocale()],"icon_url"=>$item['icon_url']);
        }

        return array(
            'data' => $newData
        );
    }

    public function showamenitiesAction(){
        ob_clean();
        $unitID = $this->_getParam('unit_id');

        $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale());
        $model = new RM_Amenities();
        $amenitiesArray = $model->getbyUnit($unitID,$iso);

        $config = new RM_AmenitiesConfig();
        $settings = $config->fetchAll("id='1'")->current()->toArray();

        $this->view->amenityData = $amenitiesArray;
        $this->view->config = $settings;

        // call the view
        echo $this->view->render('Amenities/amenities.phtml');
        die();
    }
}